package logic

import (
	"context"
	"gorm.io/gorm"
	"tiktok/model/mysql"
	"tiktok/tiktokrpc/internal/svc"
	"tiktok/tiktokrpc/tiktokrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *tiktokrpc.PerfectRequest) (*tiktokrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.TikTokUser{
		Model:   gorm.Model{ID: uint(in.UserId)},
		Name:    in.Name,
		Address: in.Address,
	}

	mysql.DB.Debug().Updates(&user)

	return &tiktokrpc.PerfectResponse{Id: int64(user.ID)}, nil
}
